﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeFarmer.DataAccess.Infrastructure
{
    public class UnitOfWork: IUnitOfWork
    {
        private readonly IDbFactory dbFactory;
        private CodeFarmerContext dbContext;

        public UnitOfWork(IDbFactory dbFactory)
        {
            this.dbFactory = dbFactory;
        }

        protected CodeFarmerContext DataContext
        {
            get
            {
                return dbContext ?? (dbContext = dbFactory.GetDb());
            }
        }

        public int Save()
        {
            return DataContext.SaveChanges();
        }
    }
}
